package org.chunchu.todo;

import javax.inject.Inject;

import org.chunchu.todo.model.Task;
import org.chunchu.todo.mvp.impl.CategoryListPresenter;
import org.chunchu.todo.mvp.impl.TaskListPresenter;
import org.chunchu.todo.mvp.impl.TaskPresenter;
import org.chunchu.todo.mvp.impl.TaskView;

import roboguice.activity.RoboActivity;
import roboguice.inject.ContentView;
import roboguice.inject.InjectView;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

@ContentView(R.layout.main)
public class Main extends RoboActivity implements TaskView {

	public static final String ACTION_ADD = "action_add";
	public static final String ACTION_EDIT = "action_edit";

	@Inject
	private TaskListPresenter taskListPresenter;
	@Inject
	private CategoryListPresenter categoryListPresenter;
	@Inject
	private TaskPresenter taskPresenter;
	@InjectView(R.id.edtName)
	private TextView txtName;
	@InjectView(R.id.edtDetail)
	private TextView txtDetail;
	// @InjectView(R.id.progressTaskLoad)
	// private ProgressBar pgsTaskLoad;
	// @InjectView(R.id.progressBar1)
	// private ProgressBar pgsLoad;
	@InjectView(R.id.addCategory)
	private Button btnAddCategory;
	@InjectView(R.id.addTask)
	private Button btnAddTask;
	@InjectView(R.id.categoryList)
	private ListView lstCategory;
	@InjectView(R.id.taskList)
	private ListView lstTask;
	@Inject
	private TaskListAdapter tasksAdapter;
	@Inject
	private CategoryListAdapter categoriesAdapter;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		taskPresenter.initializeWith(this);
		btnAddCategory.setOnClickListener(addCategoryListener);
		btnAddTask.setOnClickListener(addTaskListener);
		lstCategory.setAdapter(categoriesAdapter);
		lstTask.setAdapter(tasksAdapter);
	}

	@Override
	public void setTask(Task task) {
		task.applyTo(txtName, txtDetail);
	}

	@Override
	public void clean() {
		txtName.setText("");
		txtDetail.setText("");
	}

	private final OnClickListener addCategoryListener = new View.OnClickListener() {

		@Override
		public void onClick(View v) {
			categoryListPresenter.addItem();
		}
	};

	private final OnClickListener addTaskListener = new View.OnClickListener() {

		@Override
		public void onClick(View v) {
			taskListPresenter.addItem();
		}
	};
}